package com.zff.rental.common;

import lombok.Getter;

/**
 * @author HCY
 */
@Getter
public class BusinessException extends RuntimeException {

    private final ResultCode resultCode;

    private String msg;

    private Object data;

    public BusinessException(String msg) {
        super(msg);
        resultCode = ResultCode.CUSTOM_ERROR;
        this.msg = msg;
    }

    public BusinessException(ResultCode resultCode) {
        super(resultCode.getMsg());
        this.resultCode = resultCode;
    }

    public int getCode() {
        if (resultCode != null) {
            return resultCode.getCode();
        } else {
            return ResultCode.FAIL.getCode();
        }
    }

    public String getMsg() {
        if (msg != null) {
            return msg;
        } else if (resultCode != null) {
            return resultCode.getMsg();
        } else {
            return null;
        }
    }
}
